package cn.vconinfo.lims.delivery.mapper;

import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

public interface DoctorMapper {

    @Select("<script>" +
            "SELECT COUNT(*) FROM hospital_doctor hd\n" +
            "LEFT JOIN basic_type_info bti on hd.hospital_department_id = bti.type_info_id\n" +
            "LEFT JOIN basic_info bi on hd.hospital_id = bi.object_id\n" +
            "WHERE bi.object_type = 2\n" +
            "AND bti.type_info_type = 3\n" +
            "<if test='hospitalId!=null'>AND hospital_id  = #{hospitalId} \n</if>" +
            "AND (doctor_name  LIKE concat('%', #{search}, '%')\n" +
            "OR doctor_code  LIKE concat('%', #{search}, '%'))\n" +
            "AND hd.status = 1\n" +
            "</script>")
    Long getDoctorCount(@Param("search") String search, @Param("hospitalId") Long hospitalId);

//    @Select("<script>" +
//            "SELECT doctor_id, doctor_name, doctor_code, doctor_tel, hospital_id, hospital_department_id,\n" +
//            "hd.office_id, hd.remarks, type_info_name AS hospital_department_name, object_name AS hospital_name\n" +
//            "FROM hospital_doctor hd\n" +
//            "LEFT JOIN basic_type_info bti on hd.hospital_department_id = bti.type_info_id\n" +
//            "LEFT JOIN basic_info bi on hd.hospital_id = bi.object_id\n" +
//            "WHERE bi.object_type = 2\n" +
//            "AND bti.type_info_type = 3\n" +
//            "<if test='hospitalId!=null'>AND hospital_id  = #{hospitalId} \n</if>" +
//            "AND (doctor_name  LIKE concat('%', #{search}, '%')\n" +
//            "OR doctor_code  LIKE concat('%', #{search}, '%'))\n" +
//            "AND hd.status = 1\n" +
//            "</script>")
//    List<DoctorDTO> doctorQuery(@Param("start") Integer start, @Param("pageSize") Integer pageSize,
//                                @Param("search") String search, @Param("hospitalId") Long hospitalId);

    @Select("SELECT doctor_name FROM hospital_doctor WHERE status = 1")
    List<String> doctorNameSelect();

    @Insert("INSERT INTO hospital_doctor\n" +
            "(doctor_name, doctor_code, doctor_tel, hospital_id, hospital_department_id, office_id, remarks)\n" +
            "VALUES (#{doctorName}, #{doctorCode}, #{doctorTel}, #{hospitalId},\n" +
            "#{departmentId}, #{officeId}, #{remarks})")
    Boolean doctorAdd(@Param("doctorName") String doctorName, @Param("doctorCode") String doctorCode,
                      @Param("doctorTel") String doctorTel, @Param("hospitalId") Long hospitalId,
                      @Param("departmentId") Long departmentId, @Param("officeId") Long officeId,
                      @Param("remarks") String remarks);

    @Update("UPDATE hospital_doctor SET status = 0 WHERE doctor_id = #{doctorId}")
    Boolean doctorDelete(@Param("doctorId") Long doctorId);

//    @Update("UPDATE hospital_doctor SET doctor_name = #{doctorName}, doctor_code = #{doctorCode}, doctor_tel = #{doctorTel},\n" +
//            " hospital_id =  #{hospitalId}, hospital_department_id = #{departmentId}, office_id = #{officeId},\n" +
//            " remarks =  #{remarks} WHERE doctor_id = #{doctorId}")
//    Boolean doctorEdit(@Param("doctorId") Long doctorId, @Param("doctorName") String doctorName,
//                       @Param("doctorCode") String doctorCode, @Param("doctorTel") String doctorTel,
//                       @Param("hospitalId") Long objectTel, @Param("departmentId") Long departmentId,
//                       @Param("officeId") Long officeId, @Param("remarks") String remarks);
//
//    @Select("SELECT * FROM hospital_doctor WHERE status = 1")
//    List<DoctorDTO> getDoctor();

//    @Select("SELECT * FROM hospital_doctor WHERE status = 1 and hospital_id = #{hospitalId}")
//    List<DoctorDTO> getDoctorByHid(@Param("hospitalId") Long hospitalId);

}
